
var error;

//表单提交
document.addEventListener("click",function(evt){
    var target=evt.target;
    switch (target.id){
        case 'add-submit':
            var $id = $(".new-id").val();
            var $name = $(".new-name").val();
            var $sex = $(".new-sex input[name=sex]:checked").val();
            var $birth = $(".new-data").val();
            var $nation = $(".new-nation").val();
            var $identity =$ (".new-identity").val();
            var $place = $(".new-place").val();
            var $province = $(".new-province").val();
            var $city = $(".new-city").val();            var $county = $(".new-county").val();
            var $town = $(".new-town").val();
            var $village = $(".new-village").val();
            if ($id==""||$id==null||$name==""||$name==null||$sex==""||$sex==null||$birth==""||$birth==null||
                $nation==""||$nation==null||$identity==""||$identity==null||$place==""||$place==null||$province
                ==""||$province==null||$city==""||$city==null||$county==""||$county==null||$town==""||$town==null
                ||$village==""||$village==null){
                layer.open({
                    type: 3,
                    shadeClose: true, //点击遮罩关闭
                    content: '*为必填项，不能为空'
                });
                return false;
            }
            if (!idReg($id)) {
                layer.open({
                    type: 3,
                    shadeClose: true, //点击遮罩关闭
                    content: '请输入正确的身份证号码'
                });
                return false;
            }

            //提交失败的 JS 弹出层

            //if (error = null||error == undefined){
            //    var wait = layer.open({
            //        content: '<p><img src="images/icon_error.png"><br />提交失败</p>',
            //        shadeClose: true,
            //        time:3
            //    });
            //}
            else {
                layer.open({
                    shadeClose: false, //点击遮罩关闭
                    content: '<p><img src="images/icon_success.png"><br />提交成功</p>',
                    style:'background-color:#fff; color:#666666; border:none;text-align: center;',
                    btn:['ok'],
                    yes:function(){
                        window.location.reload();
                    }
                });
            }
            break;
        case 'maintain-submit':
            var name=$(".worker-name").val();
            var check=$(".check").is(':checked');
            if (name==null||name==""){
                layer.open({
                    type: 3,
                    shadeClose: true, //点击遮罩关闭
                    content: '请签名'
                });
                return false;
            }
            if (check==false){
                layer.open({
                    type: 3,
                    shadeClose: true, //点击遮罩关闭
                    content: '请在是否签名后面打√'
                });
                return false;
            }
            else {
                layer.open({
                    shadeClose: true, //点击遮罩关闭
                    content: '<p><img src="images/icon_success.png"><br />提交成功</p>',
                    style:'background-color:#fff; color:#666666; border:none;text-align: center;'
                });
            }
            break;
    }
},false);

//身份证号正则验证
function idReg(id){
    var reg=/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
    var result=reg.test(id)? true:false ;
    return result;
}

/*button*/
 function mychange()
 {
  document.getElementById("btn_submit,btn_submit2,btn_submit3").style.background="#2284dd";
 }
 
 
/*popup*/
document.addEventListener("click",function(evt){
	var target = evt.target;
	switch(target.id){
		case "layer1":
			var html = $('#alertdiv').html();
			layer.closeAll()
			var page1 = layer.open({
				type: 1,
				style: 'width:100%',
				shadeClose: false,
				content: html
			});
			break;
		case "layer2":
			var html = $('#alertdiv2').html();
			layer.closeAll()
			var page2 = layer.open({
				type: 1,
				style: 'width:100%',
				shadeClose: false,
				content: html
			});
			break;
			case "layer3":
			var html = $('#alertdiv3').html();
			layer.closeAll()
			var page3 = layer.open({
				type: 1,
				style: 'width:100%',
				shadeClose: false,
				content: html
			});
			break;
	}
},false);



/*menu*/
function add(e){
        e.parent().find("li").removeClass("on");
        e.addClass("on");
        var index= e.index();
        $(".rank-box").hide();
        $(".rank ul:nth-child("+(index+1)+")").show();
    }
	
	
/*position*/
jQuery(document).ready(function($) {
if (/ipad|iphone|mac/i.test(navigator.userAgent))
{
$("#header","#footer","#footer2").css("position", "static");
};
});

/*up-down*/
$(".in").bind("click", function () {
	var m = $(this).children(".menu_level").css("display");
	if(m=='none'){
		$(this).children(".menu_level").css("display","block");
		$(this).removeClass('in').addClass('on');
		
	}
	if(m=='block'){
		$(this).children(".menu_level").css("display","none");
		$(this).removeClass('on').addClass('in');
	}

     });

/*DivShow1*/
/*$(function(){
	var divpx1 = document.getElementById("divpx1");
    var divpx2 = document.getElementById("divpx2");
    divpx2.style.display = "none";
    document.getElementById("btnpx").onclick = function(){
    	var data= {};
    	var name = $("#key_name").val();
    	window.location.href = ctxPath + '/nbwx/m/list_drugs_search?name='+encodeURI(name);
        divpx1.style.display = "none"; //加上这句在显示第二个div的同时，隐藏第一个div,不加这句两个div都显示。
        divpx2.style.display = "block";
    };
	}
	);
	
$(function(){
	var divpx3 = document.getElementById("divpx3");
    var divpx4 = document.getElementById("divpx4");
    divpx4.style.display = "none";
    document.getElementById("btnpx2").onclick = function(){
        divpx3.style.display = "none"; //加上这句在显示第二个div的同时，隐藏第一个div。不加这句两个div都显示。
        divpx4.style.display = "block";
    };
	}
	);*/